﻿using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;

namespace BackupRestoreSoftwares.FormChild
{
    public partial class m_Main : UserControl
    {
        private readonly string App_path = Application.StartupPath;
        private readonly bool Is64 = Environment.Is64BitOperatingSystem;
        private readonly string Local_path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        private readonly string Program_32 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
        private readonly string Program_64 = Path.GetPathRoot(Environment.SystemDirectory) + "Program Files";
        private readonly string Roaming_path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        private string Common_path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

        #region ClearCache

        private void ClearChrome()
        {
            string chkfile = Program_32 + @"\Google\Chrome\Application\chrome.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "chrome")
                        app.Kill();
            }

            string chrome_path = Local_path + @"\Google\Chrome\User Data\Profile 1\Cache";
            if (Directory.Exists(chrome_path))
            {
                try
                {
                    var di = new DirectoryInfo(chrome_path);
                    var fi = new FileInfo(chrome_path);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(chrome_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_media = Local_path + @"\Google\Chrome\User Data\Profile 1\Media Cache";
            if (Directory.Exists(chrome_path_media))
            {
                try
                {
                    var di = new DirectoryInfo(chrome_path_media);
                    var fi = new FileInfo(chrome_path_media);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_media, "*", SearchOption.AllDirectories)
                        )
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (
                        string fileName in Directory.GetDirectories(chrome_path_media, "*", SearchOption.AllDirectories)
                        )
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_wide = Local_path + @"\Google\Chrome\User Data\WidevineCDM";
            if (Directory.Exists(chrome_path_wide))
            {
                try
                {
                    var di = new DirectoryInfo(chrome_path_wide);
                    var fi = new FileInfo(chrome_path_wide);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_wide, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (
                        string fileName in Directory.GetDirectories(chrome_path_wide, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_swift = Local_path + @"\Google\Chrome\User Data\SwiftShader";
            if (Directory.Exists(chrome_path_swift))
            {
                try
                {
                    var di = new DirectoryInfo(chrome_path_swift);
                    var fi = new FileInfo(chrome_path_swift);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_swift, "*", SearchOption.AllDirectories)
                        )
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (
                        string fileName in Directory.GetDirectories(chrome_path_swift, "*", SearchOption.AllDirectories)
                        )
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
            string chrome_path_pna = Local_path + @"\Google\Chrome\User Data\pnacl";
            if (Directory.Exists(chrome_path_pna))
            {
                try
                {
                    var di = new DirectoryInfo(chrome_path_pna);
                    var fi = new FileInfo(chrome_path_pna);
                    foreach (string fileName1 in Directory.GetFiles(chrome_path_pna, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (
                        string fileName in Directory.GetDirectories(chrome_path_pna, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete(true);
                    }
                }
                catch
                {
                }
            }
        }

        private void ClearCoRom()
        {
            string chkfile = Local_path + @"\CocCoc\Browser\Application\browser.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "browser")
                        app.Kill();
            }

            string corom_path = Local_path + @"\CocCoc\Browser\User Data\Default\Cache";
            if (Directory.Exists(corom_path))
            {
                try
                {
                    var di = new DirectoryInfo(corom_path);
                    var fi = new FileInfo(corom_path);
                    foreach (string fileName1 in Directory.GetFiles(corom_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (string fileName in Directory.GetDirectories(corom_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
        }

        private void ClearSnippets()
        {
            string chkfile = Program_32 + @"\Snippets\Snippets.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "Snippets")
                        app.Kill();
            }

            string snippets_path = Local_path + @"\Snippets\Backups";
            if (Directory.Exists(snippets_path))
            {
                try
                {
                    var di = new DirectoryInfo(snippets_path);
                    var fi = new FileInfo(snippets_path);
                    foreach (string fileName1 in Directory.GetFiles(snippets_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (
                        string fileName in Directory.GetDirectories(snippets_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
        }

        private void ClearEvernote()
        {
            string chkfile = Program_32 + @"\Evernote\Evernote\Evernote.exe";
            if (File.Exists(chkfile))
            {
                foreach (Process app in Process.GetProcesses())
                    if (app.ProcessName == "Evernote")
                        app.Kill();
            }

            string evernote_path = Local_path + @"\Evernote\Evernote\AutoUpdate";
            if (Directory.Exists(evernote_path))
            {
                try
                {
                    var di = new DirectoryInfo(evernote_path);
                    var fi = new FileInfo(evernote_path);
                    foreach (string fileName1 in Directory.GetFiles(evernote_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo1 = new FileInfo(fileName1);
                        fileInfo1.Delete();
                    }
                    foreach (
                        string fileName in Directory.GetDirectories(evernote_path, "*", SearchOption.AllDirectories))
                    {
                        var fileInfo = new DirectoryInfo(fileName);
                        fileInfo.Delete();
                    }
                }
                catch
                {
                }
            }
        }

        #endregion

        #region Button

        private void frmDevelop_Load(object sender, EventArgs e)
        {
            if (File.Exists(App_path + @"\DBBACKUP") != true)
            {
                Directory.CreateDirectory(App_path + @"\DBBACKUP");
            }
        }

        private void btn_bk_notepad_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Notepad++");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\Notepad++") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\Notepad++");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Notepad++\notepad++.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "notepad++")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Notepad++\Notepad++.rar";
                        string path_file = Roaming_path + @"\Notepad++\";
                        EasyRAR.Compress(rar_file, path_file);
                        string rar_file_plug = App_path + @"\DBBACKUP\Notepad++\plugins.rar";
                        string path_file_plug = Program_32 + @"\Notepad++\plugins\";
                        EasyRAR.Compress(rar_file_plug, path_file_plug);

                        t.Abort();
                        EasyDialog.ShowSuccessBackup("Notepad++");
                    }
                    else
                    {
                        t.Abort();
                        EasyDialog.ShowNotinstall("Notepad++");
                    }
                }
                catch
                {
                    EasyDialog.ShowContact();
                }
            }
        }

        private void btn_res_notepad_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Notepad++");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Notepad++\notepad++.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "notepad++")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Notepad++\Notepad++.rar";
                        string path_file = Roaming_path + @"\Notepad++\";
                        EasyRAR.Extract(rar_file, path_file);
                        string rar_file_plug = App_path + @"\DBBACKUP\Notepad++\plugins.rar";
                        string path_file_plug = Program_32 + @"\Notepad++\plugins\";
                        EasyRAR.Extract(rar_file_plug, path_file_plug);

                        t.Abort();
                        EasyDialog.ShowSuccessRestore("Notepad++");
                    }
                    else
                    {
                        t.Abort();
                        EasyDialog.ShowNotinstall("Notepad++");
                    }
                }
                catch
                {
                    EasyDialog.ShowContact();
                }
            }
        }

        private void btn_bk_sublime_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Sublime Text");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\SublimeText2") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\SublimeText2");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Sublime Text 2\sublime_text.exe";
                        string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                        if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                            string path_file = Roaming_path + @"\Sublime Text 2\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 2 don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                            string path_file = Roaming_path + @"\Sublime Text 2\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 2 don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_sublime_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Sublime Text");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Sublime Text 2\sublime_text.exe";
                        string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                        if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                            string path_file = Roaming_path + @"\Sublime Text 2\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 2 don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Sublime Text 2\sublime_text.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText2\Sublime2.rar";
                            string path_file = Roaming_path + @"\Sublime Text 2\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 2 don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_subtext3_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Sublime Text 3");
            if (true)
            {
                if (File.Exists(App_path + @"\DBBACKUP\SublimeText3") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\SublimeText3");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Sublime Text 3\sublime_text.exe";
                        string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                        if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                            string path_file = Roaming_path + @"\Sublime Text 3\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 3 don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                            string path_file = Roaming_path + @"\Sublime Text 3\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 3 don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_subtext3_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Sublime Text 3");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Sublime Text 3\sublime_text.exe";
                        string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                        if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                            string path_file = Roaming_path + @"\Sublime Text 3\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 3 don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Sublime Text 3\sublime_text.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "sublime_text")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\SublimeText3\Sublime3.rar";
                            string path_file = Roaming_path + @"\Sublime Text 3\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Sublime Text 3 don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_chrome_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Chrome");
            if (result == DialogResult.Yes)
            {
                ClearChrome();
                if (File.Exists(App_path + @"\DBBACKUP\Chrome") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\Chrome");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Google\Chrome\Application\chrome.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "chrome")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Chrome\User_Data.rar";
                        string path_file = Local_path + @"\Google\Chrome\User Data\";
                        EasyRAR.Compress(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Chrome don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_chrome_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Chrome");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Google\Chrome\Application\chrome.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "chrome")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Chrome\User_Data.rar";
                        string path_file = Local_path + @"\Google\Chrome\User Data\";
                        EasyRAR.Extract(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Chrome don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_opera_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Opera");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\Opera") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\Opera");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Opera\launcher.exe";
                        string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                        if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "opera")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                            string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Opera Browser don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "opera")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                            string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Opera Browser don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_opera_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Opera Browser");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Opera\launcher.exe";
                        string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                        if (File.Exists(chkfile_64) || File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "opera")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                            string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Opera Browser don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Opera\launcher.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "opera")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\Opera\Opera_Data.rar";
                            string path_file = Roaming_path + @"\Opera Software\Opera Stable\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Opera Browser don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_firrefox_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Firefox");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\Firefox") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\Firefox");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Mozilla Firefox\firefox.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "firefox")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Firefox\Firefox_Data.rar";
                        string path_file = Roaming_path + @"\Mozilla\Firefox\";
                        EasyRAR.Compress(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Mozilla Firefox don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_firefox_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Firefox");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Mozilla Firefox\firefox.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "firefox")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Firefox\Firefox_Data.rar";
                        string path_file = Roaming_path + @"\Mozilla\Firefox\";
                        EasyRAR.Extract(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Mozilla Firefox don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_corom_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Coc Coc");
            if (result == DialogResult.Yes)
            {
                ClearCoRom();
                if (File.Exists(App_path + @"\DBBACKUP\CoRom") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\CoRom");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Local_path + @"\CocCoc\Browser\Application\browser.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "browser")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CoRom\CoRom_Data.rar";
                        string path_file = Local_path + @"\CocCoc\Browser\User Data\";
                        EasyRAR.Compress(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("CoRom+ don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_corom_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Coc Coc");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Local_path + @"\CocCoc\Browser\Application\browser.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "browser")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CoRom\CoRom_Data.rar";
                        string path_file = Local_path + @"\CocCoc\Browser\User Data\";
                        EasyRAR.Extract(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("CoRom+ don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_phpDesign_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("phpDesigner");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\phpDesigner") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\phpDesigner");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\phpDesigner 8\phpDesigner.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "phpDesigner")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\phpDesigner\phpDesigner_Data.rar";
                        string path_file = Roaming_path + @"\phpDesigner\";
                        EasyRAR.Compress(rar_file, path_file);
                        File.Copy(Roaming_path + @"\phpdesigner.xml",
                            App_path + @"\DBBACKUP\phpDesigner\phpdesigner.xml", true);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("phpDesigner 8 don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_phpdesign_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("phpDesigner");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\phpDesigner 8\phpDesigner.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "phpDesigner")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\phpDesigner\phpDesigner_Data.rar";
                        string path_file = Roaming_path + @"\phpDesigner\";
                        EasyRAR.Extract(rar_file, path_file);
                        File.Copy(App_path + @"\DBBACKUP\phpDesigner\phpdesigner.xml",
                            Roaming_path + @"\phpdesigner.xml", true);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("phpDesigner 8 don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_corelx6_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Corel X6");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\CorelDraw") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\CorelDraw");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Corel\CorelDRAW Graphics Suite X6\Programs64\CorelDRW.exe";
                        if (File.Exists(chkfile_64))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "CorelDRW")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                            string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Corel Draw X6 don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite X6\Programs\CorelDRW.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "CorelDRW")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                            string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                            EasyRAR.Compress(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Backup completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Corel Draw X6 don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_corelx6_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Corel X6");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    if (Is64)
                    {
                        string chkfile_64 = Program_64 + @"\Corel\CorelDRAW Graphics Suite X6\Programs64\CorelDRW.exe";
                        ;
                        if (File.Exists(chkfile_64))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "CorelDRW")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                            string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Corel Draw X6 don't install!", "Error");
                        }
                    }
                    else
                    {
                        string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite X6\Programs\CorelDRW.exe";
                        if (File.Exists(chkfile_32))
                        {
                            foreach (Process app in Process.GetProcesses())
                                if (app.ProcessName == "CorelDRW")
                                    app.Kill();
                            string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX6.rar";
                            string path_file = Roaming_path + @"\Corel\CorelDRAW Graphics Suite X6\";
                            EasyRAR.Extract(rar_file, path_file);

                            t.Abort();
                            MessageBox.Show("Restore completed!", "Finish");
                        }
                        else
                        {
                            t.Abort();
                            MessageBox.Show("Corel Draw X6 don't install!", "Error");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_snippet_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Snippets");
            if (result == DialogResult.Yes)
            {
                ClearSnippets();
                if (File.Exists(App_path + @"\DBBACKUP\Snippets") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\Snippets");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Snippets\Snippets.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "Snippets")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Snippets\Snippets_Data.rar";
                        string path_file = Local_path + @"\Snippets\";
                        EasyRAR.Compress(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Snippets don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_snippet_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Snippets");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Snippets\Snippets.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "Snippets")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Snippets\Snippets_Data.rar";
                        string path_file = Local_path + @"\Snippets\";
                        EasyRAR.Extract(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Snippets don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        #endregion

        public m_Main()
        {
            InitializeComponent();
        }

        private void btn_bk_evernote_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Evernote");
            if (result == DialogResult.Yes)
            {
                ClearEvernote();
                if (File.Exists(App_path + @"\DBBACKUP\Evernote") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\Evernote");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Evernote\Evernote\Evernote.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "Evernote")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Evernote\Evernote_Data.rar";
                        string path_file = Local_path + @"\Evernote\Evernote\";
                        EasyRAR.Compress(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Evernote don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_evernote_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Evernote");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile = Program_32 + @"\Evernote\Evernote\Evernote.exe";
                    if (File.Exists(chkfile))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "Evernote")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\Evernote\Evernote_Data.rar";
                        string path_file = Local_path + @"\Evernote\Evernote\";
                        EasyRAR.Extract(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Evernote don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_bk_corelx3_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoBackup("Corel X3");
            if (result == DialogResult.Yes)
            {
                if (File.Exists(App_path + @"\DBBACKUP\CorelDraw") != true)
                {
                    Directory.CreateDirectory(App_path + @"\DBBACKUP\CorelDraw");
                }
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite 13\Programs\CorelDRW.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX3.rar";
                        string path_file = Roaming_path + @"\Corel\Graphics13\";
                        EasyRAR.Compress(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Backup completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X3 don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }

        private void btn_res_corelx3_Click(object sender, EventArgs e)
        {
            DialogResult result = EasyDialog.ShowYesNoRestore("Corel X3");
            if (result == DialogResult.Yes)
            {
                try
                {
                    var t = new Thread(frmMain.waitscreen);
                    t.Start();

                    string chkfile_32 = Program_32 + @"\Corel\CorelDRAW Graphics Suite 13\Programs\CorelDRW.exe";
                    if (File.Exists(chkfile_32))
                    {
                        foreach (Process app in Process.GetProcesses())
                            if (app.ProcessName == "CorelDRW")
                                app.Kill();
                        string rar_file = App_path + @"\DBBACKUP\CorelDraw\CorelX3.rar";
                        string path_file = Roaming_path + @"\Corel\Graphics13\";
                        EasyRAR.Extract(rar_file, path_file);

                        t.Abort();
                        MessageBox.Show("Restore completed!", "Finish");
                    }
                    else
                    {
                        t.Abort();
                        MessageBox.Show("Corel Draw X3 don't install!", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Please contact: caiwindao@outlook.com", "Error");
                }
            }
        }
    }
}